<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1. 这段代码里面的i会泄露到全局
        for (var i = 0; i < 10; i++) {
            console.log(i);
        }
        console.log(i);
        // 2. 下面代码的bar也是会泄露到全局的
        let foo = true
        if (foo) {
            var bar = foo * 2
            bar = something(bar) // Uncaught ReferenceError: bar is not defined
            console.log(bar);
        }
        function something(a) {
            return a * 2
        }
        console.log(bar);
    </script>
</body>

</html>